package com.chenjun.designpattern.creational.buider;

/**
 * 此段文字摘抄自《JAVA 设计模式第二版》作者Join Metsker
 * <P>
 * 构造型模式的设计是为了让类不通过类的构造函数来创建对象 例如当你需要逐步获取对象的初始值时，则可能需要使用构造器模式
 * </P>
 * 
 * @author admin
 *
 */
public class 构建器模式
{

	public static void main(String[] args)
	{
		Builder concreteBuilder = new ConcreteBuilder();
		Director director = new Director(concreteBuilder);
		director.construct();
		Product product = concreteBuilder.getResult();
	}

}

//导演类
class Director
{
	private Builder builder;
	
	public Director()
	{
		
	}
	
	public Director(Builder builder)
	{
		this.builder = builder;
	}
	
	public void construct()
	{
		builder.buildPartA();
		builder.buildPartB();
		builder.buildPartC();
	}
}

//构造器类,定义了如何创建复杂对象的各个部件,偏向于写具体的构造细节
//而至于这些构造细节的调用顺序如何,是怎么组织的 ?则是靠导演类DirectX组织在一起的
interface Builder
{
	void buildPartA();

	void buildPartB();

	void buildPartC();

	Product getResult();
}

class ConcreteBuilder implements Builder
{
	Part paerA; //需要构建的部件A
	Part paerB; //需要构建的部件B
	Part paerC; //需要构建的部件C

	@Override
	public void buildPartA()
	{
		// TODO Auto-generated method stub
		System.out.println("buildPart -A ");
	}

	@Override
	public void buildPartB()
	{
		System.out.println("buildPart -B ");
	}

	@Override
	public void buildPartC()
	{
		System.out.println("buildPart -C ");
	}

	@Override
	public Product getResult()
	{
		
		return null;
	}
}
interface Product
{
	
}
interface Part
{
	
}
